﻿using SHKF.B2C.Model.Dto;
using SHKF.B2C.Model.Dto.WorkingCenter;
using SHKF.B2C.Model.Entity.WorkingCenter;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WQDSkin.Forms.Component;

namespace SHKF.B2C.Mannage.AdminUI.View.WorkingCenter.DataWarehousInfo
{
    /// <summary>
    /// frmDataWarehousInfo.xaml 的交互逻辑
    /// </summary>
    public partial class frmDataWarehousInfo : BasePage
    {
        public frmDataWarehousInfo()
        {
            InitializeComponent();
        }

        public override void CallBack(object model)
        {
            base.CallBack(model);

            LoadData();
        }

        private void btnFind_Click(object sender, RoutedEventArgs e)
        {
            LoadData();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            doType = PageDoType.Add;

            base.Contain.Navigate("/View/WorkingCenter/DataWarehousInfo/frmDataWarehousInfoEdit", new DataWarehousInfoEntity());
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            doType = PageDoType.Update;

            if (this.dgv.SelectedItems.Count > 0)
            {
                DataWarehousInfoEntity info = (DataWarehousInfoEntity)this.dgv.SelectedValue;
                base.Contain.Navigate("/View/WorkingCenter/DataWarehousInfo/frmDataWarehousInfoEdit", info.Clone());
            }
        }

        private async void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("请确认是否要删除", "删除提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                DataWarehousInfoEntity info = (DataWarehousInfoEntity)this.dgv.SelectedValue;
                DataDto dto = await GL.HttpClientManage.DeleteDataWarehousInfo(info.SN);
                if (dto.error == null)
                {
                    this.LoadData();
                }
            }
        }

        private async void LoadData()
        {
            string text = this.txtSearch.Text;
            DataWarehousInfoListDto dto = await GL.HttpClientManage.QueryDataWarehousInfoList(text);
            if (dto.error == null)
            {
                this.dgv.ItemsSource = dto.data;
            }
            else
            {
                MessageBox.Show(dto.error.msg);
            }
        }
    }
}
